package edu.gatech.coc.sirana.graph;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

import net.util.Debug;
import net.util.File_Util;
import net.util.Out;
import edu.gatech.coc.sirana.FDA;
import edu.gatech.coc.sirana.parser.ClientLogItem;
import edu.gatech.coc.sirana.parser.ClientLogParser;
import edu.gatech.coc.sirana.util.CONSTANT;

public class _TestGraph {
	public static void main(String args[]) throws IOException{						
		String file = CONSTANT.USER_DATA_DIR + "am_userTrace.log";
		String testFile = CONSTANT.TEST_DATA_DIR + "t3.log";

		ClientLogParser clp	= new ClientLogParser(file);			
		ArrayList<ClientLogItem> interactionList	= clp.parseLogItems();	
		Out.println("---------Intearctions---------");
		for (ClientLogItem clip : interactionList){
			Out.println(clip.toString());
		}
		Out.println("---------Intearctions done--------");
		
		Out.println("\n=========" + testFile + "=========\n");		
		
//		_findSortedCirclesOnline(interactionList);
//		_findSequences(interactionList);
//		_findCyclesAndRepeatedSequence(interactionList);
		_findSRCycles(interactionList);
	}
	
	
	static void _findSortedCirclesOnline(ArrayList<ClientLogItem> interactionList) throws IOException{
		OnlineGraph og = new OnlineGraph();
		ArrayList<InteractionCycle> allSortedCircles = og.detectRecursiveInteractionCircles(interactionList);
		
		Out.println("\n\n--------- Found cycles------------");
		for (InteractionCycle ic: allSortedCircles){
			Out.println("---" + ic.toString());
		}		
		Out.println("-------" + allSortedCircles.size() + " cycles found.-------");
	}
	
	static void _findSequences(ArrayList<ClientLogItem> interactionList){
		CycleDetector cd = new CycleDetector();
		ArrayList<InteractionCycle> cycles = cd.findAllSequence(interactionList);
		Debug.println("---------Sequences found---------");
		for (InteractionCycle ic: cycles){
			Debug.println("---" + ic.toString());
		}
	}
	
	static void _findCyclesAndRepeatedSequence(ArrayList<ClientLogItem> interactionList){		
		CycleDetector cd = new CycleDetector();
		ArrayList<InteractionCycle> cycles = cd.findCyclesAndRepeatedSequence(interactionList);
		
		Debug.println("\n---------_findCyclesAndRepeatedSequence---------");
		for (InteractionCycle ic: cycles){
			Debug.println("---" + ic.toString());
		}
	}
	
	static void _findSRCycles(ArrayList<ClientLogItem> interactionList) throws IOException{			
		CycleDetector cd = new CycleDetector();
		ArrayList<InteractionCycle> cycles = cd.findCyclesAndRepeatedSequence(interactionList);
		
		OnlineGraph og = new OnlineGraph();
		og.detectRecursiveInteractionCircles(interactionList);
		//////////////////////////////////////////////////////////////////		
		ArrayList<SRCycles> srcs	= cd.findSRCycles(cycles, og);
		ArrayList<String> srcsStr	= new ArrayList<String>();
		for (SRCycles src : srcs){
			srcsStr.add("\n===successive repeated cycles===\n");
			srcsStr.add(src.toString());
			srcsStr.add("\n---successive repeated cycles done---\n");			
		}
		srcsStr.add("\n=====" + srcs.size() + " repeated cycles.\n");
		
		Debug.println(srcsStr.toString());
	}
}
	
	
